package impl;

import entity.Book;
import entity.Gift;
import factory.GiftFactory;
import interfaces.Customer;

/**
 * 顾客实现类
 * @author yy
 *
 */
public class CustomerImpl implements Customer {

	@Override
	public void showBook(Book[] books) {
		System.out.println("ID\t书名\t库存\t价格");
		for (Book book : books) {
			if(book == null){
				continue;
			}
			System.out.println(book.getId() + "\t" + book.getName() +
					"\t" + book.getStoreNum() + "\t" + book.getPrice());
		}
	}

	@Override
	public void checkBook(Book book) {
		System.out.println("----------------------------");
		System.out.println("书名：" + book.getName());
		System.out.println("数量：" + book.getBuyNum());
		System.out.println("单价：" + book.getPrice());
		System.out.println("小计：" + book.getBuyNum().intValue() *
				book.getPrice().doubleValue());
		System.out.println("----------------------------");
		if(book.getGift() != null){
			System.out.println("附赠品名称\t价格");
			System.out.println(book.getGift().getName() + "\t" + 
			book.getGift().getPrice());
		}else{
			System.out.println("你没有购买赠品");
		}
		System.out.println("总计：" + book.calcPrice());
		System.out.println("----------------------------");
	}

	@Override
	public Book buyBook(Book book, int buyNum) {
		book.setBuyNum(buyNum);
		book.setStoreNum(book.getStoreNum()-buyNum);
		checkBook(book);
		return book;
	}

	@Override
	public Gift buyGift(int giftId) {
		return GiftFactory.getGift(giftId);
	}

}
